<?php
@header("Content-Type: text/html; charset=utf-8");
@require_once '../../script/session_config.php';
@require_once '../../script/common.php';
@require_once DOCUMENT_ROOT.'/script/db.class.php';
@$db = new db();
$action = $_POST['action'];
if($action == ''){//空操作
}else if($action == 'adminLogin'){//登录后台
	$name = $_POST['name'];
	$pass = $_POST['pass'];
	//*
	if($name != '' && $pass != ''){
		//登录
		$name = $db->getQuery($name);
		$pass = $db->getQuery($pass);
		$sql = "SELECT COUNT(*) AS NUM, ID, USER FROM meinian_admin WHERE user=$name AND passwd=$pass AND statu='1' ";
		foreach ($db->doSql($sql) as $result);
//		print_r($result);
		//*
		if($result['NUM'] == 1){//登录成功
			$_SESSION['ADMIN'] = $result['ID'];
			$_SESSION['NAME'] = $result['USER'];
			$_SESSION['MENU'] = 1;
			@$db->insert('meinian_admin_logs' ,array('USER_ID'=>$_SESSION['ADMIN'],'IP'=>$_SERVER['REMOTE_ADDR'],'ACTION'=>'login'));
			echo json_encode(array('result'=>0));
		}else{//登录失败
			echo json_encode(array('result'=>1));
		}
	}else{//用户名密码空
		echo json_encode(array('result'=>9));
	}
	//*/
}else if($action == "checkName"){//检测用户名
	$name = $_POST["name"];
	if($name != ''){
		$result = $db->counts("DOG_ADMIN" ,array('USER'=>$name));
		if(!$result){//可以使用
			echo json_encode(array('result'=>$result));
		}else{//不能使用
			echo json_encode(array('result'=>$result));
		}
	}else{//用户名空
		echo json_encode(array('result'=>9));
	}
}else if($action == "changeS"){
	$cursor = $_POST['cursor'];
	if($_SESSION['ADMIN']){
		if($cursor < 16){
			$seed = 1;
			while($cursor > 1){
				$seed *= 2;
				$cursor--;
			}
			$_SESSION['MENU'] = $_SESSION['MENU']^$seed;
		}
		//echo json_encode(array('result'=>$_SESSION['MENU']));
	}
}
?>